package com.syni.mdd.sjb.community.base.quartz;

import com.syni.mdd.sjb.common.component.mybatis.community.entity.SjbQywxCompany;
import com.syni.mdd.sjb.community.base.service.CommonUtilsServce;
import com.syni.mdd.sjb.community.base.service.SjbQywxCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@EnableScheduling
public class SubiteHandlerQuartz {

    @Autowired
    CommonUtilsServce commonUtilsServce;

    @Autowired
    SjbQywxCompanyService sjbQywxCompanyService;

    @Autowired
    QywxScheduleTask qywxScheduleTask;

    /**
     * 定时任务间隔时间,当前为静态配置120分钟,之后可以移动到nacos中进行动态配置
     */
    private static final long DELAY_MINUTES = 120 * 60 * 1000;

    @Scheduled(cron = "0 0 0/2 * * ?")
    public void NotificationAuthorizationHandler() {
        sjbQywxCompanyService.syncAuthCode();
    }

    /**
     * 进行企业信息的信息同步，每两个小时同步一次
     */
//    @Scheduled(cron = "0 0 0/2 * * ?")
    @Scheduled(fixedRate = DELAY_MINUTES)
    public void syncEnterpriseMembers() {
        List<SjbQywxCompany> sjbQywxCompanies = sjbQywxCompanyService.list();
        sjbQywxCompanyService.syncEnterpriseMembers(sjbQywxCompanies);
        qywxScheduleTask.syncQywxData(sjbQywxCompanies);
    }

}
